/**
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import LogUtil from '../../common/baseUtil/LogUtil.js';
import BaseModel from "../BaseModel";
import storage from '@ohos.data.storage';

// var wifiList = [];
const PREFERENCES_PATH = '/data/accounts/account_0/appdata/com.ohos.settings/sharedPreference/SettingPreferences';
var wifiStatusPreferences = storage.getStorageSync(PREFERENCES_PATH);
const WIFISTATUS_KEY_VALUE = 'WifiStatusKeyValue';
let logUtil = new LogUtil();

export default class WifiLIstModel extends BaseModel {
    //获取wifi扫描列表数据
    //    getScanWifiInfoList(callback) {
    //        console.info('setting WifiListModel getScanWifiInfoList start')
    //        wifi.getScanInfos((result) => {
    //            var datas = JSON.parse(JSON.stringify(result));
    //            prompt.showToast({
    //                message: "获取到wifi扫描列表,当前共有" + datas.length + "个wifi",
    //                duration: 3000
    //            });
    //            var list = [];
    //            for (var i = 0; i < datas.length; i++) {
    //                var item = datas[i]
    //                var resource = {
    //                    ssid: item.ssid,
    //                    bssid: item.bssid,
    //                    securityType: item.securityType,
    //                    rssi: item.rssi,
    //                    band: item.band,
    //                    frequency: item.frequency,
    //                    timestamp: item.timestamp
    //                }
    //                list.push(resource);
    //            }
    //            callback(list);
    //        });
    //    }
    //持久化wifi开关状态
    setStorageValue(status) {
        logUtil.log('set wifi status value start ' + status);
        wifiStatusPreferences.putSync(WIFISTATUS_KEY_VALUE, status);
        wifiStatusPreferences.flushSync();
        logUtil.log('set wifi status value end');
    }
    //获取wifi开关状态
    getStorageValue() {
        logUtil.log('get wifi status value start');
        return wifiStatusPreferences.getSync(WIFISTATUS_KEY_VALUE, 0) > 0;
    }
}